home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_PICT / Source / CommentedPSCode / Ovals < prev    next >
Text File  |  1995-06-12  |  5KB  |  215 lines

  1. %BEGIN Ovals
  2.  
  3. % Copyright (C) 1993 David John Burrowes
  4. % Distributed under terms of GNU General Public License.
  5. % See COPYING.text in Convert PICT's CommentedPSCode for a copy
  6.  
  7. %%%%%%%%%%%%%
  8. %    Note:
  9. %    setupForArcPath, penWidth and penHeight defined in Common file
  10. %%%%%%%%%%%%%
  11.  
  12. %%%%%%%%%%%%%
  13. %    Name:    ovalpath
  14. %    Syntax:    top left bottom right ovalpath -
  15. %    About:    Given the coordinates for a rectangle, builds an oval.
  16. %            Note: this uses and sets the last* global values.
  17. %%%%%%%%%%%%%
  18. /ovalpath
  19. {
  20.     /lastright exch def
  21.     /lastbottom exch def
  22.     /lastleft exch def
  23.     /lasttop exch def
  24.  
  25.     newpath
  26.         lastright lastleft sub    % compute width & height
  27.         lastbottom lasttop sub
  28.         lastbottom lastleft setupForArcPath
  29.         0 360 arc
  30.     closepath
  31. } def
  32.  
  33.  
  34. %%%%%%%%%%%%%
  35. %    Name:    frameOval        [0050]
  36. %    Syntax:    top left bottom right start-angle stop-angle frameArc -
  37. %    About:    Use coords of a rectangle, this frames (outlines) the shape of
  38. %        an oval from it, using the current penWidth and penHeight.
  39. %        If the penwidth and height are both 1, then we do a special case
  40. %        framing, because it looks a bit better, and will doubtlessly be
  41. %        used frequently.  Otherwise, we use the setupForArcPath routine to
  42. %        build the path of an oval, and then build the path of one inside it.
  43. %        The inner one is inset by the penWidth & Height values, and produces
  44. %        the effect of the oval drawn with a pen of that size.
  45. %        Note that the last* values are modified and used here
  46. %%%%%%%%%%%%%
  47. /frameOval
  48. {
  49.     /lastright exch def
  50.     /lastbottom exch def
  51.     /lastleft exch def
  52.     /lasttop exch def
  53.     
  54.     gsave
  55.         penPattern usePattern
  56.         
  57.         /thewidth lastright lastleft sub def
  58.         /theheight lastbottom lasttop sub def
  59.         %
  60.         %    special case for pens that are 1 by 1 pixel
  61.         %
  62.         penHeight 1 eq
  63.         penWidth 1 eq
  64.         and
  65.         {
  66.             newpath
  67.                 thewidth theheight lastbottom lastleft setupForArcPath
  68.                 0 360 arc
  69.             closepath
  70.             stroke
  71.         }
  72.         {
  73.             %
  74.             %    More general case for penwidths and heights != 1
  75.             %
  76.             penHeight 0 gt    % don't draw with a 0 sized pen.
  77.             penWidth 0 gt
  78.             and
  79.             {
  80.                 /startmatrix  matrix  currentmatrix def
  81.                 newpath
  82.                     thewidth theheight lastbottom lastleft setupForArcPath
  83.                     0 360 arc
  84.                 closepath
  85.                     %
  86.                     %    Recover from distortions setupForArcPath did. 
  87.                     %    Calculate inner oval of the framed shape.
  88.                     %
  89.                     startmatrix setmatrix
  90.  
  91.                     /innerRight lastright penWidth sub 1 add def
  92.                     /innerTop  lasttop penHeight add 1 sub def
  93.                     /innerLeft lastleft penWidth add 1 sub def
  94.                     /innerBottom lastbottom penHeight sub 1 add def
  95.                     /innerWidth innerRight innerLeft sub def
  96.                     /innerHeight innerBottom innerTop sub def
  97.                     
  98.                     innerWidth innerHeight innerBottom innerLeft
  99.                     setupForArcPath
  100.                     360 0  arcn
  101.                 closepath
  102.                 fill
  103.             }
  104.             if
  105.         }
  106.         ifelse
  107.     grestore
  108. } def
  109.  
  110. %%%%%%%%%%%%%
  111. %    Name:    paintOval        [0051]
  112. %    Syntax:    t l b r paintOval -
  113. %    About:    pass parameters to ovalpath, and fill the resulting oval.
  114. %%%%%%%%%%%%%
  115. /paintOval
  116. {
  117.     gsave
  118.         penPattern usePattern
  119.         ovalpath
  120.         fill
  121.     grestore
  122. }
  123. def
  124.  
  125. %%%%%%%%%%%%%
  126. %    Name:    eraseOval        [0052]
  127. %    Syntax:    t l b r eraseOval -
  128. %    About:    pass parameters to ovalpath, and erase the resulting oval.
  129. %%%%%%%%%%%%%
  130. /eraseOval
  131. {
  132.     gsave
  133.         backPattern usePattern
  134.         ovalpath
  135.         fill
  136.     grestore
  137. }
  138. def
  139.  
  140. %%%%%%%%%%%%%
  141. %    Name:    invertOval        [0053]
  142. %    Syntax:    t l b r invertOval -
  143. %    About:    We can't duplicate the invert effect, so we just call ovalpath
  144. %            to consume the parameters and set last* values.
  145. %%%%%%%%%%%%%
  146. /invertOval
  147. {
  148.     gsave
  149.         ovalpath
  150.     grestore
  151. }
  152. def
  153.  
  154. %%%%%%%%%%%%%
  155. %    Name:    fillOval        [0054]
  156. %    Syntax:    t l b r fillOval -
  157. %    About:    Use the arguments to build an oval path which we then fill
  158. %%%%%%%%%%%%%
  159. /fillOval
  160. {
  161.     gsave
  162.         fillPattern usePattern
  163.         ovalpath
  164.         fill
  165.     grestore
  166. }
  167. def
  168.  
  169. %%%%%%%%%%%%%
  170. %    Name:    frameSameOval        [0058]
  171. %    Syntax:    - frameSameOval -
  172. %    About:    Using the last* values, frame an oval
  173. %%%%%%%%%%%%%
  174. /frameSameOval
  175.     { lasttop lastleft lastbottom lastright frameOval }
  176. def
  177.  
  178. %%%%%%%%%%%%%
  179. %    Name:    paintSameOval        [0059]
  180. %    Syntax:    - paintSameOval -
  181. %    About:    Using the last* values, paint an oval
  182. %%%%%%%%%%%%%
  183. /paintSameOval
  184.     { lasttop lastleft lastbottom lastright paintOval }
  185. def
  186.  
  187. %%%%%%%%%%%%%
  188. %    Name:    eraseSameOval        [005A]
  189. %    Syntax:    - eraseSameOval -
  190. %    About:    Using the last* values, erase an oval
  191. %%%%%%%%%%%%%
  192. /eraseSameOval
  193.     { lasttop lastleft lastbottom lastright eraseOval }
  194. def
  195.  
  196. %%%%%%%%%%%%%
  197. %    Name:    invertSameOval        [005B]
  198. %    Syntax:    - invertSameOval -
  199. %    About:    Using the last* values, invert an oval
  200. %%%%%%%%%%%%%
  201. /invertSameOval
  202.     { lasttop lastleft lastbottom lastright invertOval }
  203. def
  204.  
  205. %%%%%%%%%%%%%
  206. %    Name:    fillSameOval        [005C]
  207. %    Syntax:    - fillSameOval -
  208. %    About:    Using the last* values, fill an oval
  209. %%%%%%%%%%%%%
  210. /fillSameOval
  211.     { lasttop lastleft lastbottom lastright fillOval }
  212. def
  213.  
  214. %END Ovals
  215.